Skip to content

Conversation

@saifsultanc
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/2893613491/81558

Summary

Added support for a :selected modifier that would let you target the selected multi select choice by its zero-based index in our Advanced Merge Tags snippet.

David's loom:
https://www.loom.com/share/a0f523d97c964e698c7d8b0ee56e2da2

All the documentation we have on the :selected modifier:
https://gravitywiz.com/gravity-wiz-weekly-233/#h-advanced-merge-tags-target-selected-checkboxes

After the update:
https://www.loom.com/share/02471d2ea98d456c8f0a2a41af4da937

…lected multi select choice by index on the Advanced Merge Tags snippet.
@coderabbitai
Copy link

coderabbitai bot commented Apr 21, 2025

Walkthrough

The update modifies the internal logic of the handle_field_modifiers method within the GW_Advanced_Merge_Tags class. Specifically, it expands the use of the 'selected' modifier, which was previously applicable only to 'checkbox' fields, to also support 'multiselect' fields. This allows the modifier to target a selected option in a multi-select field by its zero-based index. No changes were made to the declarations or signatures of public entities.

Changes

File(s) Change Summary
gravity-forms/gw-advanced-merge-tags.php Extended the 'selected' modifier logic in handle_field_modifiers to support both 'checkbox' and 'multiselect' fields.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GW_Advanced_Merge_Tags

    User->>GW_Advanced_Merge_Tags: Call handle_field_modifiers(field, value, modifier)
    alt field type is 'checkbox' or 'multiselect' and modifier is 'selected'
        GW_Advanced_Merge_Tags->>GW_Advanced_Merge_Tags: Extract index from modifier
        GW_Advanced_Merge_Tags->>GW_Advanced_Merge_Tags: Retrieve value at specified index
        GW_Advanced_Merge_Tags-->>User: Return selected value
    else
        GW_Advanced_Merge_Tags-->>User: Process modifier as before
    end
Loading

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against 3c41658

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
gravity-forms/gw-advanced-merge-tags.php (1)

496-507: Consider adding a usage example in the comment.

While the implementation is solid, it would be helpful to add a brief usage example in the comment to make it clearer for developers how to use this feature with both field types.

 // 'selected' can be used over 'Checkbox' or 'Multi Select' field to target the selected checkbox/multiselect choice by its zero-based index.
+// Example: {Multi Select Field:1:selected[0]} returns the first selected option
 if ( $field->type == 'checkbox' || $field->type == 'multiselect' ) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c8de01 and 3c41658.

📒 Files selected for processing (1)
  • gravity-forms/gw-advanced-merge-tags.php (1 hunks)
🔇 Additional comments (2)
gravity-forms/gw-advanced-merge-tags.php (2)

496-497: Enhancement looks good - expands :selected modifier to work with multi-select fields.

The update appropriately extends the :selected modifier functionality to handle both checkbox and multiselect field types. The comment has been properly updated to reflect this expanded functionality, and the condition now correctly checks for both field types.

This change aligns perfectly with the PR objective of adding the :selected modifier to target selected multi-select choices by their zero-based index, similar to how it already works with checkboxes.


497-507:

❓ Verification inconclusive

Verify the expected output format for multiselect fields.

Ensure that multiselect fields indeed return their values as comma-separated strings like checkboxes do. If they have a different format, additional handling might be needed.


🏁 Script executed:

#!/bin/bash
# Search for any related multiselect field processing code
rg -A 3 "multiselect.*value" --type php

Length of output: 41


Verify multiselect value formatting
The code below assumes $value for multiselect fields is a comma‑separated string (just like checkboxes) and uses explode(',', $value). Please confirm that Gravity Forms indeed returns multiselect values in that format. If it uses a different delimiter or structure, you’ll need to adjust the parsing logic accordingly.

• File: gravity‑forms/gw‑advanced‑merge‑tags.php
• Lines: 497‑507
• Snippet:

if ( $field->type == 'checkbox' || $field->type == 'multiselect' ) {
    $index = $modifier_options;
    if ( $index !== 'selected' && is_numeric( $index ) ) {
        $index = intval( $index );
    } else {
        break;
    }

    $value_array = explode( ',', $value );
    return rgar( $value_array, $index );
}

@saifsultanc saifsultanc merged commit e4d9afb into master May 1, 2025
3 of 4 checks passed
@saifsultanc saifsultanc deleted the saif/add/81558-add-multiselect-selected branch May 1, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants